<?php

class M_captcha extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    public function them_moi($time,$ip_address,$word)
    {
        $data = array(
            'captcha_time' =>$time,
            'ip_address'=>$ip_address,
            'word'=>$word
        );
        $query = $this->db->insert_string('captcha',$data);
        $this->db->query($query);
    }
    public function xoa_lay_captcha($captcha)
    {
        $expiration = time() - 7200;
        $this->db->query("delete from captcha where captcha_time <".$expiration);
        
        $sql = "select count(*) as count from captcha where word = ? and ip_address = ? and captcha_time > ?";
        $binds = array($captcha,$this->input->ip_address(),$expiration);
        $query = $this->db->query($sql,$binds);
        return $query->row();
    }
}

?>